
/* Generated by Interface Builder */

#import "ClockView.h"
#import <dpsclient/wraps.h>
#import <appkit/Control.h>
#import <math.h>

#define LEFT_MARGIN (-40.0)
#define RIGHT_MARGIN 0.0
#define TOP_MARGIN 30.0
#define BOTTOM_MARGIN (-30.0)
#define TWO_PI 6.28318


@implementation ClockView

+newFrame:(const NXRect *)tF {
    self = [super newFrame:tF];
    hour = 3;
    minute = 60;
    return self;
}

- setHour:sender
{
	hour = [sender intValue];
	[hourText setIntValue:hour];
	[self display];
    return self;
}

- setMinute:sender
{
	minute = [sender intValue];
	[minuteText setIntValue:minute];
	[self display];
    return self;
}

- setHourText:anObject
{
    hourText = anObject;
    return self;
}

- setMinuteText:anObject
{
    minuteText = anObject;
    return self;
}

- drawSelf:(NXRect*)r :(int)c
{
	char str[10];
	int i;
	float centerX, centerY, scale;
	float minuteHandLength, hourHandLength;
	centerX = (bounds.size.width-RIGHT_MARGIN-LEFT_MARGIN)/2.0;
	centerY = (bounds.size.height-TOP_MARGIN-BOTTOM_MARGIN)/2.0;
	scale = (bounds.size.width-RIGHT_MARGIN-LEFT_MARGIN);
	minuteHandLength = scale*0.4;
	hourHandLength = scale*0.3;
    PSsetgray(NX_WHITE);
    NXRectFill(r);

	PStranslate(centerX+LEFT_MARGIN, centerY+BOTTOM_MARGIN);
	
	// draw numbers
	PSsetgray(NX_BLACK);
    PSselectfont("Helvetica", 80.0);
    for (i=1; i<=12; i++) {
		PSmoveto( sin((float)i/12.0*TWO_PI) * scale*0.4,
					cos((float)i/12.0*TWO_PI) * scale*0.4);
    	sprintf(str, "%d", i);
    	PSshow(str);
	}

    // minute hand
    PSsetgray(NX_BLACK);
    PSsetlinewidth(20.0);
    PSnewpath();
    	PSmoveto(0.0, 0.0);
    	PSrlineto( sin((float) minute/60.0*TWO_PI) * minuteHandLength,
					cos((float) minute/60.0*TWO_PI) * minuteHandLength);
    PSstroke();
    
    // hour hand
	PSsetgray(NX_BLACK);
    PSsetlinewidth(30.0);
	PSnewpath();
    	PSmoveto(0.0, 0.0);
    	PSrlineto( sin((float) hour/12.0*TWO_PI) * hourHandLength,
					cos((float) hour/12.0*TWO_PI) * hourHandLength);
    PSstroke();
    
    return self;
}

@end
